#ifndef __BSP_UART_FIFO_H__
#define __BSP_UART_FIFO_H__

#include <stdint.h>
#include "bsp_typedef.h"
#include "bsp_queue.h"

/* 配置是否使用UARTx_FIFO接口*/
#define USE_UART0_FIFO     (1)
#define USE_UART1_FIFO     (1)
#define USE_UART2_FIFO     (1)
#define USE_UART3_FIFO     (1)
#define USE_UART4_FIFO     (1)
#define USE_UART5_FIFO     (1)
#define USE_UART6_FIFO     (1)
#define USE_UART7_FIFO     (1)


/* 配置UARTx发送缓冲区的大小 */
#define UART0_SEND_BUFF_SIZE    500
#define UART1_SEND_BUFF_SIZE    500
#define UART2_SEND_BUFF_SIZE    500
#define UART3_SEND_BUFF_SIZE    500
#define UART4_SEND_BUFF_SIZE    500
#define UART5_SEND_BUFF_SIZE    500
#define UART6_SEND_BUFF_SIZE    500
#define UART7_SEND_BUFF_SIZE    500

/* 配置UARTx接收缓冲区的大小 */
#define UART0_RECV_BUFF_SIZE    500
#define UART1_RECV_BUFF_SIZE    500
#define UART2_RECV_BUFF_SIZE    500
#define UART3_RECV_BUFF_SIZE    500
#define UART4_RECV_BUFF_SIZE    500
#define UART5_RECV_BUFF_SIZE    500
#define UART6_RECV_BUFF_SIZE    500
#define UART7_RECV_BUFF_SIZE    500

typedef enum
{
    UART_FIFO_COM0 = 0,
    UART_FIFO_COM1,
    UART_FIFO_COM2,
    UART_FIFO_COM3,
    UART_FIFO_COM4,
    UART_FIFO_COM5,
    UART_FIFO_COM6,
    UART_FIFO_COM7
}uart_fifo_com_e;

typedef void (*uart_fifo_send_cb_t)(void *arg);
typedef void (*uart_fifo_recv_cb_t)(void *arg);


/* 初始化 */
BOOL uart_fifo_init(uart_fifo_com_e com, uint32_t baudval);

/* 设置波特率 */
BOOL uart_fifo_set_baud(uart_fifo_com_e com, uint32_t baudval);

/* 注册发送回调函数 */
BOOL uart_fifo_reg_send_cb(uart_fifo_com_e com, 
                           uart_fifo_send_cb_t send_befor,
                           uart_fifo_send_cb_t send_ing,
                           uart_fifo_send_cb_t send_over);

/* 注册接收回调函数 */
BOOL uart_fifo_reg_recv_cb(uart_fifo_com_e com, 
                           uart_fifo_recv_cb_t recv_idle,
                           uart_fifo_recv_cb_t recv_ing);
                           

/* 获取已经收到的数据个数（单位：字节） */
int32_t uart_fifo_get_recv_len(uart_fifo_com_e com);

/* 清除FIFO已经收到的数据 */
BOOL uart_fifo_clear_recv(uart_fifo_com_e com);

/* 清除FIFO中已经装填的要发送的数据（基本用不上） */
BOOL uart_fifo_clear_send(uart_fifo_com_e com);

/* 发送数据 */
int32_t uart_fifo_send(uart_fifo_com_e com, uint8_t *buff, int32_t len);

/* 接收数据 */
int32_t uart_fifo_recv(uart_fifo_com_e com, uint8_t *buff, int32_t len);

#endif
